package graph.day16;

import java.util.*;

public class Bellman_ford_circle {

    static class Edge {
        int to;
        int val;

        public Edge(int to, int val) {
            this.to = to;
            this.val = val;
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        //用邻接表存储图
        List<List<Edge>> grid = new ArrayList<>(n + 1);
        for (int i = 0; i <= n; i++) {
            grid.add(new ArrayList<>());
        }
        for (int i = 0; i < m; i++) {
            int from = sc.nextInt();
            int to = sc.nextInt();
            int val = sc.nextInt();
            grid.get(from).add(new Edge(to, val));
        }
        int[] minDist = new int[n + 1];
        int[] visited = new int[n + 1];
        Arrays.fill(minDist, Integer.MAX_VALUE);
        int start = 1;
        int end = n;
        minDist[start] = 0;
        //定义队列
        Queue<Integer> queue = new LinkedList<>();
        queue.offer(start);
        // 记录节点加入队列几次
        visited[start]++;
        while (!queue.isEmpty()) {
            int cur = queue.poll();
            for (Edge edge : grid.get(cur)) {
                int from = cur;
                int to = edge.to;
                int val = edge.val;
                if (minDist[from] != Integer.MAX_VALUE && minDist[from] + val < minDist[to]) {
                    minDist[to] = minDist[from] + val;
                    queue.offer(to);
                    visited[to]++;
                    if (visited[to] == n) {
                        System.out.println("circle");
                        return;
                    }
                }
            }
        }
        if (minDist[end] == Integer.MAX_VALUE) {
            System.out.println("unconnected");
        } else {
            System.out.println(minDist[end]);
        }
    }
}
